package Leetcode第一期;

import java.util.Stack;

/**
 * @author : K k
 * @date : 15:55 2020/9/4
 */
public class 牛牛的01游戏 {
    public static String niuniu(){
        String s=new String("00110001");
        char[] s1 = s.toCharArray();
        char c;
        Stack<Character> stack=new Stack<>();
        stack.push(s1[0]);

        for(int i=1;i<s1.length;i++){
            if (!stack.isEmpty()){
                c=stack.peek();
                if (c==s1[i]){
                    if (c=='0'){
                        stack.pop();
                        s1[i--]='1';
                    }else{
                        stack.pop();
                    }
                }else {
                    stack.push(s1[i]);
                }
            }else {
                stack.push(s1[i]);
            }
        }
        StringBuilder stringBuilder=new StringBuilder("");
        while(!stack.isEmpty()){
           stringBuilder.append(stack.pop());
        }

        return stringBuilder.reverse().toString();

    }

    public static void main(String[] args) {
        System.out.println(niuniu());
    }
}
